$(function(){
	if(localStorage.getItem("products")) {
	var result = localStorage.getItem("products");
	var data = JSON.parse(result);
	$('.shoppingcar_total').html('<td class="total_img"><img src='+data[0].pImgSrc+' /></td>'
	                             +'<td class="total_text"><span>'+data[0].pName+'</span>
	                             <br><b>适配机型</b></td>'
	                             +'<td class="total_price">'+data[0].prcie+'</td>'
	                             +'<td class="total_count" style="border:none">
	                             <input type="number" id="number"
	                             value=1 style="height:15px;width:42px;margin-left:34%;" onchange="change()"></td>'
	                             +'<td class="total_priceone">'+data[0].prcie+'</td>'
	                             +'<td class="total_delet" onclick="del()"><img src="images/shop1.jpg" /></td>')
	}
})
									function change(){
										if($('#number').val()<1){
											$('#number').val('1')
										}
										$('.total_priceone').html(59*$('#number').val()+'元')
										$('#allnum').html(59*$('#number').val()+'元')
									}
									function del(){
										localStorage.removeItem("products");
										$('.shoppingcar_total').html('')
										
									}
									<script type="text/javascript">



									
//改变商品数量
var prices = $('.td-sum .td-inner .J_ItemSum');
function changeNum(gid,obj,x){
	var price = {$price}[gid].price;
	var num = parseFloat($(obj).parent().children('.text_box').val());
	num += x;
	if(num <= 0){
		num = 0;
	}
	$(prices).eq(gid).html((price*(num)).toFixed(2));
	sumPrice(num);
};
//计算商品总价格
function sumPrice(){
	var total = 0;
	var bool = true;
	var goodsNum = 0;
	$('.cart-checkbox .check').not($('#J_SelectAllCbx2')).each(function(i){
		if($(this).attr('checked')){
			total += parseFloat($(prices).eq(i).html());
			++goodsNum;
		}else{
			bool = false;
		}
	});
	if(bool){
		$('#J_SelectAllCbx2').attr('checked',true);
	}else{
		$('#J_SelectAllCbx2').attr('checked',false);
	}
	total = total.toFixed(2);
	$('#J_Total').html(total);
	$('#J_SelectedItemsCount').html(goodsNum);
}
//全选
function allSelect(obj){
	var i = $('.cart-checkbox .check').index($('#J_SelectAllCbx2'));
	if($('#J_SelectAllCbx2').attr('checked')){
		$('.cart-checkbox .check').not($(obj)).attr('checked',true);
	}else{
		$('.cart-checkbox .check').not($(obj)).attr('checked',false);
	}
	sumPrice();
};
//付款
var goods = {$price};
function payBill(){
	var gids = '';
	var nums = '';
	$('.cart-checkbox .check').not($('#J_SelectAllCbx2')).each(function(i){
		if($(this).attr('checked')){
			gids += ',' + goods[i].gid;
			nums += ',' + parseFloat($('.item-amount .sl .text_box').eq(i).val());
		};
		gid = gids.substr(1);
		num = nums.substr(1);
	});
	if(gid == ''){
		Showbo.Msg.alert('请选择至少一件商品！！！');
	}else{
		location.href = '/index/orders/pay?gid='+gid+'&num='+num;
	}
};
//删除购物车商品
function deleteGoods(carid){
	$.post('/index/shop_cars/deleteCar',{carid:carid},function(){
		history.go(0);
	})
}
//全选后的删除
$('.deleteAll').click(function(){
	var gids = '';
		$('.cart-checkbox .check').not($('#J_SelectAllCbx2')).each(function(i){
		if($(this).attr('checked')){
			gids += ',' + goods[i].gid;
		};
		gid = gids.substr(1);
	});
	deleteGoods(gid);
});
</script>
